<?php
/**
 * CompleXml Framework
 *
 * @category   CompleXml
 * @package    CompleXml_Argv
 * @copyright  Copyright (c) 2008 Andrey Kucherenko
 * @license    New BSD License
 * @version    $Id: Argv.php 8 2008-11-13 14:50:42Z kucherenko.andrey $
 */

require_once 'CompleXml/Dataset/Abstract.php';
class CompleXml_Dataset_Argv extends CompleXml_Dataset_Abstract
{
    public function __construct ()
    {
        global $argv;
		$result = array();
		if (!empty($argv)){
			foreach ($argv as $key =>$value) {
				$res = explode('=',$value, 2);
				
				$field  = str_replace('-','', $res[0]);
				
				if (empty($field)){
					continue;
				}
				
				if (@!is_null($res[1])){
					$result[$field] = $res[1];
				}elseif (strpos($res[0], '-')===0){
					$result[$field] = true;
				}else {
					$result[$key] = $res[0];
				}
			}
		}
		parent::__construct($result);
    }
} 